package com.vch.ws;

import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;

import javax.xml.namespace.QName;

public class TestVCHService {

	static Properties prop = new Properties();
	static InputStream input = null;
	static String urlCall = "";
	
	public String callVCHService(String data){
		
		String retData = "";
		
		try {
			
			input = new FileInputStream("wsconfig.properties");
			prop.load(input);
			
			urlCall = prop.getProperty("VCHURL");
			
			QName qName = new QName("http://www.voucher.ws.application.muangthai.co.th/","InsertVoucherService");
			 
			URL url = new URL(urlCall);
			
			InsertVoucherService_Service wsClient = new InsertVoucherService_Service(url,qName);
			InsertVoucherService wsPort = wsClient.getInsertVoucherWsImplPort();
			
			VoucherRequest request = new VoucherRequest();
			request.setPolicyNumber(data);
			VoucherResponse response = wsPort.insertVoucher(request);
			
			System.out.println("VoucherPolicy: " + response.getVoucherPolicy());
			System.out.println("VoucherTranId: " + response.getVoucherTranId());
			System.out.println("VoucherNember: " + response.getVoucherNumber());
			retData = response.getVoucherNumber().toString();
			
			}catch (Exception e) {
			 e.printStackTrace();
			}
		
		return retData;
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			
			input = new FileInputStream("wsconfig.properties");
			prop.load(input);
			
			urlCall = prop.getProperty("VCHURL");
			
			QName qName = new QName("http://www.voucher.ws.application.muangthai.co.th/","InsertVoucherService");
			 
			URL url = new URL(urlCall);
			 
			InsertVoucherService_Service wsClient = new InsertVoucherService_Service(url,qName);
			InsertVoucherService wsPort = wsClient.getInsertVoucherWsImplPort();
			
			VoucherRequest request = new VoucherRequest();
			request.setPolicyNumber("999999901");
			VoucherResponse response = wsPort.insertVoucher(request);
			
			System.out.println("VoucherPolicy: " + response.getVoucherPolicy());
			System.out.println("VoucherTranId: " + response.getVoucherTranId());
			System.out.println("VoucherNember: " + response.getVoucherNumber());

			}catch (Exception e) {
			 e.printStackTrace();
			}
	}

}
